package com.hoow.shakoow.ai.network

import com.hoow.shakoow.utils.UserStateUtil
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response

class ResponseInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request: Request = chain.request()
//        Log.d(ResponseInterceptor::class.java.simpleName, "Url: " + request.url)
//        Log.d(ResponseInterceptor::class.java.simpleName, "body: " + request.body)
        val response = chain.proceed(request)
        response.header(ApiAiHeaderMap.KEY_TOKEN)?.let {
            println("cur token: $it")
            if (it.isNotBlank()) {
                UserStateUtil.saveToken(it)
            }
        }
        return response
    }
}
